import React, { Component } from 'react'
import Header from "../../components/Header/Header"
import "./Cate.less"
import {$pre} from "../../http/http"
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { actions, getCate, getGoods,getN,} from "../../store/modules/cate";
class Cate extends Component {
   componentDidMount(){
     let {
       cate: {reqCate,reqGoods}
     } = this.props;
     reqCate();
     reqGoods();
   }
    render() {
        let { Lcate,goods,n,} = this.props;
        return (
            <div>
                <Header title="分类"></Header>
                <div className="wrap">
                    <div className="left">
                        {
                            Lcate.map((item, index) => {
                                return <button key={item.id} className={index ===n ? 'active' : ''} onClick={() =>this.getgoods(item.id)}>
                                    {item.catename}
                                </button>
                            })
                        }
                    </div>
                    <div className="right">
                        {
                            goods.map(item=>{
                                return (
                                   <div key={item.id} onClick={()=>this.toDetail(item.id)}>
                                    <img src={$pre+item.img} alt="" />
                                    <div>价格：{item.price}</div>
                                    <div>市场价格：{item.market_price}</div>
                                   </div>
                                )
                            })
                        }
                     
                    </div>
                </div>
            </div>
        )
    }
}
const mapStateToProps = (state) => {
  return {
    Lcate:getCate(state),
    goods:getGoods(state),
    n:getN(state)
  };
};
const mapDispatchToProps = (dispatch) => {
  return {
    cate: bindActionCreators(actions, dispatch),
  };
};
export default connect(mapStateToProps, mapDispatchToProps)(Cate);
